package com.why.servicecms.controller.admin;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.why.commonresults.Result;
import com.why.servicecms.bean.CrmBanner;
import com.why.servicecms.service.CrmBannerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: guli_parent
 * @description:管理banner
 * @author: @why
 * @create: 2021-02-14 17:18
 **/
@RestController
@RequestMapping("/servicecms/crm-banner/admin")
@CrossOrigin
public class BannerAdminController {

    @Autowired
    CrmBannerService service;


    /**
     * 分页查询banner
     *
     * @param pageNo
     * @param limit
     * @return
     */
    @GetMapping("pageBanner/{pageNo}/{limit}")
    public Result pageBanner(@PathVariable long pageNo, @PathVariable long limit) {

        Page<CrmBanner> page = new Page<>(pageNo, limit);
        service.page(page, null);
        return Result.ok().data("pageData", page.getRecords()).data("total", page.getTotal());
    }


    @ApiOperation(value = "获取Banner")
    @GetMapping("get/{id}")
    public Result get(@PathVariable String id) {
        CrmBanner banner = service.getById(id);
        return Result.ok().data("item", banner);
    }

    @ApiOperation(value = "新增Banner")
    @PostMapping("save")
    public Result save(@RequestBody CrmBanner banner) {
        service.save(banner);
        return Result.ok();
    }

    @ApiOperation(value = "修改Banner")
    @PutMapping("update")
    public Result updateById(@RequestBody CrmBanner banner) {
        service.updateById(banner);
        return Result.ok();
    }

    @ApiOperation(value = "删除Banner")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable String id) {
        service.removeById(id);
        return Result.ok();
    }


}
